package com.gdface.admin.gdface_attend.listView;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;

import com.gdface.admin.gdface_attend.R;

import net.gdface.face.Entity.Att_user;

import java.util.List;

public class Adapter_User extends HBaseAdapter<Att_user> {

    private Activity context;
    private Custom_User callBack;
    public Adapter_User(List<Att_user> data,Activity context) {
        super(data, R.layout.list_item_user);
        this.context = context;
        this.callBack = (Custom_User) context;
    }

    @Override
    public void setData(ViewHolder holder, Att_user t) {
        final Long id = t.getId();
        String permission = "员工";
        String isonjob = "在职";
        if(0 == t.getPermission()){
            permission = "员工";
        }else{
            permission = "管理员";
        }

        if(0 == t.getIsOnJob()){
            isonjob = "在职";
        }else{
            isonjob =  "离职";
        }


//        holder.setImg(R.id.user_item_iv,context, PfsBioInfo.PHOTO_DB_PATH +  t.getId() + ".JPEG")
                holder.setText(R.id.user_item_id,""+id).setText(R.id.user_item_company, t.getCompany())
                .setText(R.id.user_item_userID, t.getUserNo())
                .setText(R.id.user_item_isonjob, isonjob)
                .setText(R.id.user_item_update_time,t.getUpdataTime())
                .setText(R.id.user_item_permission, permission).setOnclick(R.id.user_item_compile, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        new AlertDialog.Builder(context).setTitle("删除员工信息").setMessage("员工信息删除后无法恢复，确认删除？").setPositiveButton("删除", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            callBack.DeleteUser(id);
                            }
                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).show();
                    }
                });

    }


}